package com.iptv.grape.bu.imp;

import android.view.KeyEvent;

import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.AppState;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.bu.IKeyEventPorc;
import com.iptv.grape.domain.Channel;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.event.data.LiveData;
import com.iptv.grape.util.AppConstant;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.video.XMediaPlayer;

import org.greenrobot.eventbus.EventBus;

// 直播时候按 上键 换台
@AppState(isShowLiveMenu = false,curPlayType="Live", curLiveType="ALL",keyVals = {19},isIgnoreTimeLiveUI=true)
public class ChangeLiveGoUp implements IKeyEventPorc {
    @Override
    public void onKeyDownEvent(BaseActivity context, XMediaPlayer mediaPlayer, GrapeContext grapeContext, KeyEvent event) {
        if(grapeContext.getChannelDLinkList().getCurChannel() != null) {
            LiveData quitliveData = new LiveData(grapeContext.getChannelDLinkList().getCurChannel(),"0","23","1");
            EventBus.getDefault().post(new EventArgs(AppConstant.DataLive, AppConstant.DataAcquisition,quitliveData));

            Channel channel = grapeContext.getChannelDLinkList().getCurChannel().getNext();
            if (channel != null) {
                if(grapeContext.curLiveType().equals("Back")){
                    GrapeContext.curGrapeContext().setCurPlayType("Live");
                    GrapeContext.curGrapeContext().setCurLiveType("Live");
                    GrapeContext.curGrapeContext().removeChannelBillUI(context);
                }
                if(grapeContext.curLiveType().equals("Time")){
                    grapeContext.setCurLiveType("Live");
                    grapeContext.removeTimeLiveFragment(context);
                }
                channel.playChannel();
                LiveData liveData = new LiveData(channel,"0","23","0");
                EventBus.getDefault().post(new EventArgs(AppConstant.DataLive, AppConstant.DataAcquisition,liveData));
            }
        }
    }
}
